package com.ssyc.gsk_parents.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ssyc.common.utils.ScreenUtils;
import com.ssyc.common.utils.UiUtils;
import com.ssyc.gsk_parents.R;
import com.ssyc.gsk_parents.bean.LessonRecordInfo;

import java.util.List;

/**
 * 课时记录列表适配器
 * Created by Administrator on 2018/6/19 0019.
 */

public class LessonRecodAdapter extends BaseQuickAdapter<LessonRecordInfo.DataBean, BaseViewHolder> {
    private Context context;

    private RelativeLayout.LayoutParams lp;
    private LinearLayout.LayoutParams lpOut;

    public LessonRecodAdapter(Context context, int layoutResId, @Nullable List<LessonRecordInfo.DataBean> data) {
        super(layoutResId, data);
        this.context = context;
        int width = ScreenUtils.getScreenWidth(context) * 15 / 37;
        int height = width * 8 / 15;
        lp = new RelativeLayout.LayoutParams(width, height);
        int outWidth = (ScreenUtils.getScreenWidth(context) - UiUtils.dp2px(10 + 10)) / 2;
        int outHeight = outWidth * 106 / 185;
        lpOut = new LinearLayout.LayoutParams(outWidth, outHeight);
    }

    @Override
    protected void convert(BaseViewHolder helper, LessonRecordInfo.DataBean item) {
        RelativeLayout rlOut = helper.getView(R.id.rl_out);
        ImageView iv_state = helper.getView(R.id.iv_state);
        TextView tv_lesson_name = helper.getView(R.id.tv_lesson_name);
        TextView tv_time = helper.getView(R.id.tv_time);

        rlOut.setLayoutParams(lpOut);
        //条目外层布局
        LinearLayout llOut = helper.getView(R.id.ll_out);
        lp.addRule(RelativeLayout.CENTER_IN_PARENT);
        llOut.setLayoutParams(lp);

        //设置第几课
        tv_lesson_name.setText("第"+(getData().size()-helper.getPosition())+"次课");

        //设置时间
        tv_time.setText(item.getDate());

        if("0".equals(item.getType())){
            //已到
            llOut.setBackgroundResource(R.drawable.parent_lesson_record_normal);
            iv_state.setImageResource(R.drawable.parent_already);
        }else{
            //旷课
            llOut.setBackgroundResource(R.drawable.parent_lesson_record_selectedl);
            iv_state.setImageResource(R.drawable.parent_absenteeism);
        }
    }
}
